import axios from 'axios'
import { Message } from 'element-ui';
// 创建axios实例
const service = axios.create({
  //baseURL: 'http://localhost:5000/', // api的base_url
   baseURL: 'http://47.92.39.231:5000/', // api的base_url
  timeout: 120000 // 请求超时时间
})
// request拦截器
service.interceptors.request.use(config => {
  config.headers['Content-Type'] = "application/json; charset=utf-8";
  return config
}, error => {
  // Do something with request error
  // console.log(error) // for debug
  Promise.reject(error)
})
// respone拦截器
service.interceptors.response.use(
  response => {
      const res = response.data
      if (res.code == 201) { //----------------------------------错误
        Message({
          message: res.msg,
          type: 'error'
        });
      }
      else if (res.code == 200) { //------------------------------成功
        Message({
          message: res.msg,
          type: 'success'
        });
      }
      return res
    },
    error => {
      Message({
        message: '服务器异常,请稍后重试',
        type: 'error'
      });
      return Promise.reject(error)
    }
  )

export default service
